﻿#ifndef MYGRAPHICSVIEW_H
#define MYGRAPHICSVIEW_H

#include "common.h"
#include "TmItem/tm_robotitem.h"

#include "map/mapedit.h"

#include <QThread>
//.yaml

class MyGraphicsView : public QGraphicsView
{
    Q_OBJECT
public:
    MyGraphicsView(QWidget *parent = nullptr);
    ~MyGraphicsView();

    void on_LoadMapfilePath(QString Path);//加载地图

    void on_setMapYaml(QString yamlPath);//获取地图数据

    void on_setPixmap(QPixmap PixmapPath,QString PixmapID);//打开地图文件

    void on_setPointLine(QString JsonPath);//或者json数据路线

    void on_UpdateLine(QGraphicsItem *Pointitem);//刷新路线

    double on_X_calibration(bool isSave,double value);//x轴坐标转换
    double on_Y_calibration(bool isSave,double value);//y轴坐标转换

    void slot_OpenMapEdit(bool isOpen);

    void slot_LinerAutoSetBazierPos(QGraphicsItem *Pointitem);//直线 自动移动bazier焦点
public slots:
    void slot_Map_Edit(QString Type = "",QString data = "");

    void slot_CurrentAction(int ActionType = 0,QString data = "");

    void slot_SaveMap(QString Path);
    bool savePixmapAsPgm(const QPixmap &pixmap, const QString &fileName);
    void slot_NaviRosData(QString type,QStringList dataList);

    void slot_mapPixmap(QPixmap pixmap);
signals:
    void sig_MapMessage(QString Type,QString data);
    void sig_MapLineMessage(QString Type,QVariantMap data);

    void sig_MapEditData(QString type,QStringList data);
    void sig_MapEditPixmap(QPixmap pixmap,QString data);
protected:
    virtual void mousePressEvent(QMouseEvent *event);
    virtual void mouseReleaseEvent(QMouseEvent *event);
    virtual void mouseMoveEvent(QMouseEvent *event);
    virtual void wheelEvent(QWheelEvent *event);
public:
    QList<QGraphicsEllipseItem*> m_bezileItemList;
    bool m_is_ActionIng = false;//是否执行动作指令,执行期间不接受定位和激光数据
    QGraphicsRectItem* m_EraserItem = nullptr;//橡皮擦
    QGraphicsScene*         m_scene = nullptr;
    QGraphicsPixmapItem*    m_PixmapItem = nullptr;
    QPixmap                 m_pixmap;//地图bmp
    QPoint                  m_mousePos;//鼠标当前位置//
    QString                 m_mouseClickItemID;//当前点击的item ID



    int m_CurrentAction = Action_NULL;//当前执行的动作
    bool is_Xiugai_Line = false;//正在点击Point、bezier

    QGraphicsItem *is_Line_startItem = NULL;
    QGraphicsItem *is_Line_endItem = NULL;

    TM_RobotItem  *m_RobotItem = NULL;
    bool is_RobotAddScan = false;//是否显示机器人item

    MapEdit *m_newMapEdit = nullptr;
    QThread m_MapEditThread;
};

#endif // MYGRAPHICSVIEW_H
